<template>
  <div class="wrap">
    <!--头部-->
    <div class="header">
      <!--头部上半部分-->
      <div class="top">
        <!--上半部分版心-->
        <div class="topMain">
          <div class="left">
            <h5>&nbsp;&nbsp;&nbsp;</h5>
            <p>
              <a href="##" class="login"></a>
              <a href="##"></a>
            </p>
          </div>
          <div class="right"></div>
        </div>
      </div>
      <!--头部下半部分-->
      <div class="bottom">
        <!--下半部分版心-->
        <div class="bottomMain">
          <h1></h1>
        </div>
      </div>
    </div>

    <!--商品内容区-->
    <div class="main">
      <!--版心-->
      <div class="mainCon">
        <!--路径导航-->
        <div class="conPoin">
          <a href="###">首页</a>
          <i>ღ</i>
          <a href="###">所有运动</a>
          <i>ღ</i>
          <a href="###">跑鞋</a>
          <i>ღ</i>
          <a>男性</a>
        </div>
        <!--商品信息-->
        <div class="infoWrap">
          <div class="previwWrap">
            <div class="previw">
              <div class="zoomImgBox">
                <img :src="goodsImages[currentIndex]" alt="" />
              </div>
            </div>
            <div class="thumbnail">
              <a href="##" class="prev">&lt;</a>
              <div class="itemWrap">
                <ul class="list">
                  <li v-for="(item, index) in goodsImages" :key="index">
                    <img
                      @click="change(index)"
                      :src="item"
                      :class="{ active: currentIndex == index }"
                    />
                  </li>
                </ul>
              </div>
              <a href="##" class="next">&gt;</a>
            </div>
          </div>
          <!--商品信息区域-->
          <!--商品信息区域-->
          <div class="info">
            <!--上半部分-->
            <!-- v-for="(c1,index) in searchList" :key="c1.name" -->
            <div class="infoTop">
              <h3>{{ userObj.name }}</h3>

              <!--价格区域-->
              <div class="priceArea">
                <div class="priceTop">
                  <p class="title">价&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;格</p>
                  <p class="price">
                    <i>￥</i>
                    <em>{{ userObj.price }}</em>
                    <br />
                    ⭐⭐⭐⭐⭐ <i>累计评价</i>
                    <span>100条评论</span>
                  </p>

                  <p class="remark"></p>
                </div>
                <div class="priceBottom">
                  <div>
                    <span>{{ userObj.message }} </span>
                  </div>
                </div>
              </div>
              <div class="support">
                <div></div>
                <div></div>
              </div>
            </div>
            <!--选择区域-->
            <div class="choose">
              <div class="chooseArea">
                <dl>
                  <dt>颜色</dt>
                  <dd>深蓝色</dd>
                </dl>
              </div>
              <div class="addCarArea">
                <div class="control">
                  <i>尺寸</i>
                  <!-- <input type="text"  style="width:400px"> -->
                  <span
                    role="button"
                    style="
                      position: relative;
                      overflow: hidden;
                      display: flex;
                      padding: 8px 12px;
                      cursor: pointer;
                      border: 1px solid #edeff1;
                      background-color: #fff;
                      width: 400px;
                      height: 20px;
                    "
                    >尺寸</span
                  >
                </div>
                <br /><br /><br />
                <div class="addCar">
                  <!-- <button  >加入购物车</button> -->
                  <a class="addCart"  @click="addCart">加入购物车</a>
                </div>
                <br />
                <br />
                <div>
                  <span>
                    单笔订单满99免运费。(健身大器械、乒乓球桌、自行车除外)
                  </span>
                  <br />
                  <span>
                    门店自提订单免运费。自行车门店自提订单使用内部专线物流，受中途转运和门店配货车次的影响，物流时效较长。
                  </span>
                  <br />
                  <span>
                    顺丰配送，部分商品已开通次日达，目前仅限上海，北京，深圳，广州和苏州，其他地区将陆续开通。
                    *订单具体配送条件，以配送页面次日达物流提示为准。
                  </span>
                </div>
              </div>
            </div>
          </div>

          <!--下半-->
        </div>
      </div>
    </div>
    <!--下半部分-->

    <div class="halfbottom">
      <!-- <div class="navigation" style="display:black">
      <div>产品详情</div>
      <div>推荐搭配</div>
      <div>顾客评价</div>
      </div> -->

      <div class="product" style="text-align: center">
        <h1>产品特点</h1>
        <img src="../../assets/picture/3.png" alt="" />
        <br />
        <br />

        <h1>选购贴士</h1>
        <img src="../../assets/picture/4.png" alt="" />

        <br />
        <br />

        <h1>规格说明</h1>
        <img src="../../assets/picture/2.png" alt="" />

        <br />
        <br /><br />
        <br />
        <h1>搭配推荐</h1>
        <div class="phone">
          <ul>
            <li style="margin-left: 10px">
              <a href="##" style="margin-left: 10px">
                <img src="../../assets/picture/1.jpg" style="width: 200px" />
                <p>KALENJI</p>
                <span> 男士快干系列慢跑体恤 </span>
                <h3 style="font-size: 10px">⭐⭐⭐⭐⭐(169)</h3>
              </a>
            </li>
            <li style="margin-left: 10px">
              <a href="##" style="margin-right: 10px">
                <img src="../../assets/picture/1.jpg" />
                <p>KALENJI</p>
                <span> 男士快干系列慢跑体恤 </span>
                <h3 style="font-size: 10px">⭐⭐⭐⭐⭐(169)</h3>
              </a>
            </li>
            <li style="margin-left: 10px">
              <a href="##">
                <img src="../../assets/picture/1.jpg" />
                <p>KALENJI</p>
                <span> 男士快干系列慢跑体恤 </span>
                <h3 style="font-size: 10px">⭐⭐⭐⭐⭐(169)</h3>
              </a>
            </li>
          </ul>
        </div>
        <br />
        <br /><br />
        <br />
        <h1>相似推荐</h1>
        <div class="phone">
          <ul>
            <li style="margin-left: 10px">
              <a href="##" style="margin-left: 10px">
                <img src="../../assets/picture/1.jpg" style="width: 200px" />
                <p>KALENJI</p>
                <span> 男士快干系列慢跑体恤 </span>
                <h3 style="font-size: 10px">⭐⭐⭐⭐⭐(169)</h3>
              </a>
            </li>
            <li style="margin-left: 10px">
              <a href="##" style="margin-right: 10px">
                <img src="../../assets/picture/1.jpg" />
                <p>KALENJI</p>
                <span> 男士快干系列慢跑体恤 </span>
                <h3 style="font-size: 10px">⭐⭐⭐⭐⭐(169)</h3>
              </a>
            </li>
            <li style="margin-left: 10px">
              <a href="##">
                <img src="../../assets/picture/1.jpg" />
                <p>KALENJI</p>
                <span> 男士快干系列慢跑体恤 </span>
                <h3 style="font-size: 10px">⭐⭐⭐⭐⭐(169)</h3>
              </a>
            </li>
          </ul>
        </div>
        <br /><br />
      </div>
      <div style="font-size: 20px">
        <div style="background: #f5f5f5; height: 60px">
          <h1 style="color: pink; font-size: 40px">用户评价⭐⭐⭐⭐⭐ 5/5</h1>
        </div>
        <br />
        <span
          >⭐⭐⭐⭐⭐RUN ACTIVE 男士跑鞋-深棕
          <br />

          脚感超级舒适，款式也好看，性价比高，值得推荐 无
        </span>

        <br />
        <br />

        <span
          >⭐⭐⭐⭐⭐RUN ACTIVE 男士跑鞋-深棕
          <br />

          脚感超级舒适，款式也好看，性价比高，值得推荐 无
        </span>
        <br />
        <br />

        <span
          >⭐⭐⭐⭐⭐RUN ACTIVE 男士跑鞋-深棕
          <br />

          脚感超级舒适，款式也好看，性价比高，值得推荐 无
        </span>
        <br />
        <br />

        <span
          >⭐⭐⭐⭐⭐RUN ACTIVE 男士跑鞋-深棕
          <br />

          脚感超级舒适，款式也好看，性价比高，值得推荐 无
        </span>
      </div>
      <br />
      <br /><br /><br />

      <div style="text-align: center">
        <h1>猜你喜欢</h1>
        <img src="../../assets/picture/7.png" alt="" />
        <br /><br /><br />
        <img src="../../assets/picture/11.png" alt="" />
      </div>
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";
export default {
  name: "detail",
  data() {
    return {
      c1: "",
      id: "",
      currentIndex: 0,
      skuId: 0,
      skuNum: 1,
    };
  },
  mounted() {
    this.getSearchList();
  },

  methods: {
    change(index) {
      console.log(this.currentIndex);
      this.currentIndex = index;
    },
    // ...mapActions(['getGoodsListInfo'])

    async getSearchList() {
      await this.$store.dispatch("getSearchList");
      this.skuId = parseInt(this.userObj.skuId);
    },
    async addCart() {
      //1、得先发请求，在后端数据库存储我们的购物车信息
      try {
        //2、当请求成功以后，我们会收到添加购物车成功的消息
        await this.$API.reqAddOrUpdateShopCart(this.skuId,this.skuNum)
        //3、然后再跳转到添加购物车成功页面
        alert("添加购物车成功，准备自动跳转到添加购物车成功页面");

        //需要传递两个数据   一个是商品的数量  一个是商品的详情
        //params参数和query参数  携带的时候都是简单数据，如果是一个对象复杂数据，尽量不要使用
        //如果需要传递复杂的数据，推荐使用存储方案
        // localStorage  / sessionStorage
        // 存储数据的时候只认字符串，如果存储的不是字符串，会自动转化为字符串再存储
        //  可以认为是前端浏览器当中的两个小型数据库
        // localStorage 存储数据的时候永久存储   数据不关心浏览器关不关闭
        // sessionStorage  存储数据是临时存储   关闭浏览器重新打开数据就不存在了
        // cookie和session是用来解决无状态协议而出现的

        sessionStorage.setItem("SKUINFO_KEY", JSON.stringify(this.skuInfo));
        this.$router.push({
          name: "shopcart",
          params: {
            skuId: this.skuId,
            skuNum: this.skuNum,
          },
        });
      } catch (error) {
        alert("添加购物车失败");
      }
    },
  },
  computed: {
    ...mapState({
      searchList: (state) => state.detail.searchList || [],
    }),
    userObj() {
      return this.searchList.find((item) => item.id == this.id) || {};
    },
    goodsImages() {
      return this.userObj.goodsImages || [];
    },
  },
  watch: {
    $route: {
      immediate: true,
      handler() {
        this.id = this.$route.query.id;
      },
    },
  },
  //点击添加购物车
};
</script>

<style>
.wrap {
  width: 100%;
}
.wrap .header {
  width: 100%;
}
.wrap .header .top {
  width: 100%;
  background: #eaeaea;
  height: 30px;
}
.wrap .header .top .topMain {
  width: 1200px;
  height: 100%;
  margin: 0 auto;
}
.wrap .header .top .topMain .left {
  width: 200px;
  height: 100%;
  float: left;
  line-height: 30px;
}
.wrap .header .top .topMain .left > h5 {
  float: left;
}
.wrap .header .top .topMain .left > p {
  float: left;
  margin-left: 5px;
}
.wrap .header .top .topMain .left > p .login {
  border-right: 1px solid #b3aeae;
  padding-right: 5px;
}
.wrap .header .top .topMain .right {
  height: 100%;
  float: right;
  line-height: 30px;
  font-size: 0;
}
.wrap .header .top .topMain .right nav > a {
  font-size: 12px;
  padding: 0 10px;
}
.wrap .header .top .topMain .right nav > a + a {
  border-left: 1px solid #b3aeae;
}
.wrap .header .bottom {
  width: 100%;
}
.wrap .header .bottom .bottomMain {
  width: 1200px;
  margin: 0 auto;
  *zoom: 1;
}
.wrap .header .bottom .bottomMain::after {
  content: "";
  display: block;
  clear: both;
}
.wrap .header .bottom .bottomMain h1 {
  float: left;
}
.wrap .header .bottom .bottomMain h1 img {
  width: 175px;
  height: 56px;
  margin-top: 25px;
  margin-left: 45px;
  margin-bottom: 20px;
}
.wrap .header .bottom .bottomMain .search {
  float: right;
  margin-top: 35px;
}
.wrap .header .bottom .bottomMain .search > input {
  width: 490px;
  height: 32px;
  box-sizing: border-box;
  padding: 0 4px;
  border: 3px solid #ea4a36;
  float: left;
}
.wrap .header .bottom .bottomMain .search button {
  width: 68px;
  height: 32px;
  line-height: 32px;
  text-align: center;
  background: #ea4a36;
  color: #fff;
  border: none;
  float: left;
}
.wrap .typeNav {
  width: 100%;
  border-bottom: 2px solid #e1251b;
  *zoom: 1;
}
.wrap .typeNav::after {
  content: "";
  display: block;
  clear: both;
}
.wrap .typeNav .navMain {
  width: 1200px;
  margin: 0 auto;
}
.wrap .typeNav .navMain > h3 {
  float: left;
  width: 210px;
  height: 50px;
  text-align: center;
  line-height: 50px;
  color: #fff;
  background: #e1251b;
}
.wrap .typeNav .navMain > div {
  float: left;
}
.wrap .typeNav .navMain > div > a {
  margin: 0 22px;
  font-size: 16px;
  color: #333;
  line-height: 50px;
}
.wrap .main {
  width: 100%;
}
.wrap .main .mainCon {
  width: 1200px;
  margin: 15px auto 0;
}
.wrap .main .mainCon .conPoin {
  padding: 9px 15px 9px 0;
}
.wrap .main .mainCon .conPoin > a {
  padding: 0 5px;
}
.wrap .main .mainCon .infoWrap {
  margin: 5px 0 15px;
  *zoom: 1;
}
.wrap .main .mainCon .infoWrap::after {
  content: "";
  display: block;
  clear: both;
}
.wrap .main .mainCon .infoWrap .previwWrap {
  width: 400px;
  float: left;
}
.wrap .main .mainCon .infoWrap .previwWrap .previw {
  width: 100%;
  height: 400px;
  border: 1px solid #dfdfdf;
  position: relative;
}
.wrap .main .mainCon .infoWrap .previwWrap .previw .zoomImgBox {
  width: 100%;
  height: 100%;
  position: relative;
}
.wrap .main .mainCon .infoWrap .previwWrap .previw .zoomImgBox > img {
  width: 100%;
}
.wrap .main .mainCon .infoWrap .previwWrap .previw .zoomImgBox .mask {
  width: 200px;
  height: 200px;
  background: rgba(255, 255, 255, 0.5);
  border: 1px solid #ddd;
  position: absolute;
  left: 0;
  top: 0;
}
.wrap .main .mainCon .infoWrap .previwWrap .previw .bigImgBox {
  width: 100%;
  height: 100%;
  position: absolute;
  left: 420px;
  top: 0;
  border: 1px solid #ddd;
  overflow: hidden;
}
.wrap .main .mainCon .infoWrap .previwWrap .previw .bigImgBox img {
  width: 800px;
  height: 800px;
}
.wrap .main .mainCon .infoWrap .previwWrap .thumbnail {
  width: 100%;
  margin-top: 5px;
  *zoom: 1;
}
.wrap .main .mainCon .infoWrap .previwWrap .thumbnail::after {
  content: "";
  display: block;
  clear: both;
}
.wrap .main .mainCon .infoWrap .previwWrap .thumbnail > a {
  width: 10px;
  height: 54px;
  line-height: 54px;
  text-align: center;
  border: 1px solid #ccc;
  background: #ebebeb;
}
.wrap .main .mainCon .infoWrap .previwWrap .thumbnail > a.prev {
  float: left;
  margin-right: 4px;
}
.wrap .main .mainCon .infoWrap .previwWrap .thumbnail > a.next {
  float: right;
}
.wrap .main .mainCon .infoWrap .previwWrap .thumbnail .itemWrap {
  float: left;
  width: 372px;
  height: 56px;
  overflow: hidden;
  position: relative;
}
.wrap .main .mainCon .infoWrap .previwWrap .thumbnail .itemWrap .list {
  width: 9999px;
  position: absolute;
  left: 0;
  top: 0;
  transition: 0.5s;
  *zoom: 1;
}
.wrap .main .mainCon .infoWrap .previwWrap .thumbnail .itemWrap .list::after {
  content: "";
  display: block;
  clear: both;
}
.wrap .main .mainCon .infoWrap .previwWrap .thumbnail .itemWrap .list > li {
  width: 50px;
  height: 50px;
  float: left;
  border: 1px solid #ccc;
  padding: 2px;
  margin-right: 20px;
}
.wrap
  .main
  .mainCon
  .infoWrap
  .previwWrap
  .thumbnail
  .itemWrap
  .list
  > li
  > img {
  width: 100%;
  height: 100%;
}
.wrap .main .mainCon .infoWrap .info {
  width: 700px;
  float: right;
}
.wrap .main .mainCon .infoWrap .info .infoTop > h3 {
  line-height: 21px;
  margin-top: 15px;
}
.wrap .main .mainCon .infoWrap .info .infoTop > p {
  color: #e12228;
  margin-top: 15px;
}
.wrap .main .mainCon .infoWrap .info .infoTop .priceArea {
  width: 100%;
  /* background: #fee9ec; */
  padding: 7px;
  margin-top: 10px;
  line-height: 28px;
}
.wrap .main .mainCon .infoWrap .info .infoTop .priceArea .priceTop {
  *zoom: 1;
}
.wrap .main .mainCon .infoWrap .info .infoTop .priceArea .priceTop::after {
  content: "";
  display: block;
  clear: both;
}
.wrap .main .mainCon .infoWrap .info .infoTop .priceArea .priceTop p {
  float: left;
}
.wrap .main .mainCon .infoWrap .info .infoTop .priceArea .priceTop p.remark {
  float: right;
}
.wrap .main .mainCon .infoWrap .info .infoTop .priceArea .priceTop p.title {
  margin-right: 15px;
}
.wrap .main .mainCon .infoWrap .info .infoTop .priceArea .priceTop p.price {
  color: orange;
}
.wrap .main .mainCon .infoWrap .info .infoTop .priceArea .priceTop p.price i {
  font-size: 16px;
}
.wrap .main .mainCon .infoWrap .info .infoTop .priceArea .priceTop p.price em {
  font-size: 24px;
  font-weight: bold;
}
.wrap
  .main
  .mainCon
  .infoWrap
  .info
  .infoTop
  .priceArea
  .priceTop
  p.price
  span {
  font-size: 12px;
}
.wrap .main .mainCon .infoWrap .info .infoTop .priceArea .priceBottom {
  margin-top: 10px;
  line-height: 28px;
  *zoom: 1;
}
.wrap .main .mainCon .infoWrap .info .infoTop .priceArea .priceBottom::after {
  content: "";
  display: block;
  clear: both;
}
.wrap .main .mainCon .infoWrap .info .infoTop .priceArea .priceBottom > p {
  float: left;
  margin-right: 15px;
}
.wrap .main .mainCon .infoWrap .info .infoTop .priceArea .priceBottom > div {
  float: left;
  width: 520px;
}
.wrap .main .mainCon .infoWrap .info .infoTop .priceArea .priceBottom > div i {
  padding: 3px;
  background: #c81623;
  color: #fff;
}
.wrap
  .main
  .mainCon
  .infoWrap
  .info
  .infoTop
  .priceArea
  .priceBottom
  > div
  span {
  color: #999;
}
.wrap .main .mainCon .infoWrap .info .infoTop .support {
  border-bottom: 1px solid #ededed;
  padding-bottom: 5px;
}
.wrap .main .mainCon .infoWrap .info .infoTop .support > div {
  *zoom: 1;
  margin-top: 10px;
  line-height: 28px;
}
.wrap .main .mainCon .infoWrap .info .infoTop .support > div::after {
  content: "";
  display: block;
  clear: both;
}
.wrap .main .mainCon .infoWrap .info .infoTop .support > div > p {
  float: left;
}
.wrap .main .mainCon .infoWrap .info .infoTop .support > div > p.title {
  margin-right: 15px;
}
.wrap .main .mainCon .infoWrap .info .infoTop .support > div > p.text {
  color: #999;
}
.wrap .main .mainCon .infoWrap .info .choose {
  margin-top: 10px;
  line-height: 28px;
}
.wrap .main .mainCon .infoWrap .info .choose .chooseArea dl {
  margin: 13px 0;
  *zoom: 1;
}
.wrap .main .mainCon .infoWrap .info .choose .chooseArea dl::after {
  content: "";
  display: block;
  clear: both;
}
.wrap .main .mainCon .infoWrap .info .choose .chooseArea dl dt {
  float: left;
  margin-right: 15px;
}
.wrap .main .mainCon .infoWrap .info .choose .chooseArea dl dd {
  float: left;
  padding: 2px 14px;
  margin-right: 5px;
  line-height: 24px;
  color: #666;
  border-left: 1px solid #eee;
  border-top: 1px solid #eee;
  border-right: 1px solid #ddd;
  border-bottom: 1px solid #ddd;
}
.wrap .main .mainCon .infoWrap .info .choose .chooseArea dl dd:nth-of-type(1) {
  color: red;
}
.wrap .main .mainCon .infoWrap .info .choose .addCarArea {
  *zoom: 1;
}
.wrap .main .mainCon .infoWrap .info .choose .addCarArea::after {
  content: "";
  display: block;
  clear: both;
}
.wrap .main .mainCon .infoWrap .info .choose .addCarArea .control {
  width: 55px;
  margin-right: 15px;
  position: relative;
  float: left;
}
.wrap .main .mainCon .infoWrap .info .choose .addCarArea .control > input {
  width: 38px;
  height: 37px;
  line-height: 37px;
  text-align: center;
  border: 1px solid #ddd;
  color: #555;
  outline: none;
}
.wrap .main .mainCon .infoWrap .info .choose .addCarArea .control > a {
  width: 15px;
  height: 18px;
  text-align: center;
  line-height: 18px;
  background: #f1f1f1;
  position: absolute;
  right: 1px;
  border: 1px solid #ddd;
}
.wrap .main .mainCon .infoWrap .info .choose .addCarArea .control > a.plus {
  top: 0;
}
.wrap .main .mainCon .infoWrap .info .choose .addCarArea .control > a.minus {
  top: 19px;
}
.wrap .main .mainCon .infoWrap .info .choose .addCarArea .addCar {
  float: left;
}
.wrap .main .mainCon .infoWrap .info .choose .addCarArea .addCar > button {
  padding: 0 25px;
  height: 36px;
  line-height: 36px;
  background: #fdd935;
  color: #fff;
  font-size: 16px;
  border: none;
  outline: none;
  cursor: pointer;
}

.wrap .halfbottom .navigation {
  width: 100%;
  height: 50px;
}
.wrap .halfbottom .paroduct {
  text-align: center;
}
.phone {
  width: 1200px;
  height: 330px;
  /* background: pink; */
  margin: 50px auto 0;
}

.phone ul li {
  width: 269px;
  height: 328px;
  border: 1px solid #e1251b;
  float: left;
  margin-right: 25px;
}

.phone ul li a {
  display: block;
  height: 328px;
  color: #333;
}

.phone ul li a img {
  width: 200px;
  margin: 5px auto 0;
}

.phone ul li a p {
  line-height: 28px;
  text-indent: 5px;
  padding-left: 10px;
  margin-top: 28px;
  background: #fafafa;
}

.phone ul li a h3 {
  color: #e1251b;
  font-size: 20px;
  font-weight: 400;
  background: #fafafa;
  height: 39px;
  line-height: 39px;
  padding-left: 10px;
}
.addCart {
  width: 400px;
  height: 32px;
  line-height: 32px;
  text-align: center;
  background: yellow;
  float: left;
  border: none;
  cursor: pointer;
}
</style>
